<?php 
class Country_Widget_CountryBodyController extends Engine_Content_Widget_Abstract{
    
    public function indexAction(){
        $viewer = Engine_Api::_()->user()->getViewer();
        if( !Engine_Api::_()->core()->hasSubject() ) {
          return $this->setNoRender();
        }
        
        $subject = Engine_Api::_()->core()->getSubject();
        
        if(!$subject instanceof Country_Model_Country){
            return $this->setNoRender();
        }
        $this->getElement()->removeDecorator('title');
        $this->view->subject_id = $subject_id = $subject->getIdentity();
        
        $countryfieldTb = Engine_Api::_()->getDbTable('countryfields','country');
        $fieldTb = Engine_Api::_()->getDbTable('fields','country');
        
        $select = $countryfieldTb->select()
                                ->distinct()
                                ->setIntegrityCheck(false)
                                ->from('engine4_country_countryfields as a')
                                ->join('engine4_country_fields as b','a.field_id = b.field_id','b.title' )
                                ->where('a.country_id = ?', $subject_id)
                                ;
      // echo $select;die;                         
        $this->view->result = $result = $countryfieldTb->fetchAll($select);
        
        //echo $result;die;
    }
    
    
}
?>